<!--
/**
 * author: vformAdmin
 * email: vdpadmin@163.com
 * website: https://www.vform666.com
 * date: 2021.08.18
 * remark: 如果要分发VForm源码，需在本文件顶部保留此文件头信息！！
 */
-->

<template>
  <div class="container-wrapper" :class="[customClass]">
    <slot></slot>

    <div class="widget-action" v-if="designer.selectedId === widget.id && !widget.internal">
      <i :title="i18nt('designer.hint.selectParentWidget')" @click.stop="selectParentWidget(widget)">
        <VfIcon name="iv-icon-back" />
      </i>
      <i v-if="!!parentList && (parentList.length > 1)"
        :title="i18nt('designer.hint.moveUpWidget')"
        @click.stop="moveUpWidget()">
        <VfIcon name="iv-icon-move-up" />
      </i>
      <i v-if="!!parentList && (parentList.length > 1)"
        :title="i18nt('designer.hint.moveDownWidget')"
        @click.stop="moveDownWidget()">
        <VfIcon name="iv-icon-move-down" />
      </i>
      <i v-if="widget.type === 'table'"
        :title="i18nt('designer.hint.insertRow')"
        @click.stop="appendTableRow(widget)">
        <VfIcon name="iv-icon-insert-row" />
      </i>
      <i v-if="widget.type === 'table'"
        :title="i18nt('designer.hint.insertColumn')"
        @click.stop="appendTableCol(widget)">
        <VfIcon name="iv-icon-insert-column" />
      </i>
      <i v-if="(widget.type === 'grid') || (widget.type === 'table')"
        :title="i18nt('designer.hint.cloneWidget')"
        @click.stop="cloneContainer(widget)">
        <VfIcon name="iv-icon-clone" />
      </i>
      <i :title="i18nt('designer.hint.remove')" @click.stop="removeWidget">
        <VfIcon name="iv-icon-delete" />
      </i>
    </div>

    <div class="widget-label drag-handler" v-if="designer.selectedId === widget.id && !widget.internal">
      <i :title="i18nt('designer.hint.dragHandler')"><VfIcon name="iv-icon-drag" /></i>
      <i>{{i18n2t(`designer.widgetLabel.${widget.type}`, `extension.widgetLabel.${widget.type}`)}}</i>
      <i v-if="widget.options.hidden === true"><VfIcon name="iv-icon-hide" /></i>
    </div>
  </div>
</template>

<script>
  import i18n from "@/utils/i18n";
  import containerMixin from "@/components/form-designer/form-widget/container-widget/containerMixin";


  export default {
    name: "container-wrapper",
    mixins: [i18n, containerMixin],
    components: {
    },
    props: {
      widget: Object,
      parentWidget: Object,
      parentList: Array,
      indexOfParentList: Number,
      designer: Object,
    },
    computed: {
      customClass() {
        return !!this.widget.options.customClass ? this.widget.options.customClass.join(' ') : ''
      },

    }
  }
</script>

<style lang="scss" scoped>
@import '@/components/form-designer/form-widget/styles/widget-action.scss';

.container-wrapper {
  position: relative;
  margin-bottom: 5px;
}
</style>
